#include "baobiao_form.h"
#include "ui_baobiao_form.h"
#include<QDebug>
baobiao_form::baobiao_form(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::baobiao_form)
{
    ui->setupUi(this);


    //预约报表饼状图
//    QVector<SectorInfo> result;
//    SectorInfo info;
//    info.description = "预定中";
//    info.percent = 0.3*100;
//    result.push_back(info);
//    info.description = "预订结算";
//    info.percent = (1 - 0.3)*100;
//    result.push_back(info);
//    ui->widget_2->setData(result);

}
//预约报表图
//查询当天数据中各个位置的流量//最多显示6条最大流量数据
void baobiao_form::book_his_show(){
    QSqlQuery query;
    ui->widget_3->SetMaxValue(10);//设置最大值
    ui->widget_3->Clear();
    QString str_book1=QString("select COUNT(*) as c,place_id from book where to_days(time) = to_days(NOW()) GROUP BY place_id ORDER BY c desc;");
    QString place_id;
    int num,i=0;
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            qDebug()<<num<<place_id;
            ui->widget_3->AddItem(place_id,num);
        }

    }
}
void baobiao_form::book_bar_show(){
    ui->widget_2->clearMask();
    QVector<SectorInfo> result;
    SectorInfo info;
    QSqlQuery query;
    QString str_book1=QString("select COUNT(*) as c,place_id from book where to_days(time) = to_days(NOW()) GROUP BY place_id ORDER BY c desc;");
    QString place_id;
    int num,i=0,sum=0;
    //统计总数
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            sum++;
        }
    }
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            info.description = place_id;
            info.percent = float(num)/sum*100;
            result.push_back(info);
        }
    ui->widget_2->setData(result);
}
}
//停车图
void baobiao_form::stop_his_show(){
    QSqlQuery query;
    ui->widget_5->SetMaxValue(10);//设置最大值
    ui->widget_5->Clear();
    QString str_book1=QString("select COUNT(*) as c,place_id from stopinfo where to_days(intime) = to_days(NOW()) GROUP BY place_id ORDER BY c desc;");
    QString place_id;
    int num,i=0;
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            ui->widget_5->AddItem(place_id,num);
        }

    }
}
void baobiao_form::stop_bar_show(){
    ui->widget_4->clearMask();
    QVector<SectorInfo> result;
    SectorInfo info;
    QSqlQuery query;
    QString str_book1=QString("select COUNT(*) as c,place_id from stopinfo where to_days(intime) = to_days(NOW()) GROUP BY place_id ORDER BY c desc;");
    QString place_id;
    int num,i=0,sum=0;
    //统计总数
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            sum++;
        }
    }
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            info.description = place_id;
            info.percent = float(num)/sum*100;
            result.push_back(info);
        }
    ui->widget_4->setData(result);
}
}
//结算图
void baobiao_form::con_his_show(){
    QSqlQuery query;
    ui->widget_12->SetMaxValue(2300);//设置最大值
    ui->widget_12->Clear();
    QString str_book1=QString("select SUM(amount) as s,consuption.place_id from consuption,stopinfo where stopinfo.id=consuption.stopinfo_id and to_days(outtime) = to_days(NOW()) GROUP BY consuption.place_id ORDER BY s desc;");
    QString place_id;
    int num,i=0;
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            ui->widget_12->AddItem(place_id,num);
        }

    }

}
void baobiao_form::con_bar_show(){
    ui->widget_11->clearMask();
    QVector<SectorInfo> result;
    SectorInfo info;
    QSqlQuery query;
    QString str_book1=QString("select SUM(amount) as s,consuption.place_id from consuption,stopinfo where stopinfo.id=consuption.stopinfo_id and to_days(outtime) = to_days(NOW()) GROUP BY consuption.place_id ORDER BY s desc;");
    QString place_id;
    int num,i=0,sum=0;
    //统计总数
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            sum++;
        }
    }
    if (query.exec(str_book1)){
        while(query.next()&&i<10){
            i++;
            num=query.value(0).toInt();
            place_id=query.value(1).toString();
            info.description = place_id;
            info.percent = float(num)/sum*100;
            result.push_back(info);
        }
    ui->widget_11->setData(result);
}
}
baobiao_form::~baobiao_form(){
    delete ui;
}
